package team.zero.lemon.module.sys.service;

import team.zero.lemon.common.exception.CustomException;
import team.zero.lemon.common.persistence.Page;
import team.zero.lemon.common.service.CrudService;
import team.zero.lemon.module.sys.dao.IOrgDao;
import team.zero.lemon.module.sys.dao.IUserDao;
import team.zero.lemon.module.sys.entity.Organization;
import team.zero.lemon.module.sys.entity.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by bolin on 2016/5/10.
 */
@Service
public class OrgService  extends CrudService<IOrgDao, Organization> {
    @Transactional
    public boolean deleteAll() {
        try {
            dao.deleteAll();
            return true;
        } catch (Exception e) {
            throw new CustomException(e.getMessage());
        }
    }
    public List<Organization> findAllOrg() {
        try {
            return dao.findAll();
        } catch (Exception e) {
            throw new CustomException(e);
        }
    }

    public List<Organization> findAllOrgUser(Organization organization) {
        try {
            return dao.findAllOrgUser();
        } catch (Exception e) {
            throw new CustomException(e);
        }
    }

    public Page<Organization> findOrgByParentId(Organization organization) {
        try {
            List<Organization> organizations = dao.findPage(organization);
            organization.page.setList(organizations);
            return organization.page;
        } catch (Exception e) {
            throw new CustomException(e);
        }
    }
    public List<Organization> findPortInfo() {
        try {
            return dao.findPortInfo();
        } catch (Exception e) {
            throw new CustomException(e);
        }
    }
    public List<Organization> findPortAndWarehouse() {
        try {
            return dao.findPortAndWarehouse();
        } catch (Exception e) {
            throw new CustomException(e);
        }
    }

    public List<Organization> findWarehouse() {
        try {
            return dao.findWarehouse();
        } catch (Exception e) {
            throw new CustomException(e);
        }
    }



}
